package com.samsung.sharepoint;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/* Creates an array adapter that takes the list, defines the views and inserting it into the view. This adapter is used by attach.class */
public class FileArrayAdapter extends ArrayAdapter<option> {

	private Context c;
	private int id;
	private List<option> items;
	ImageView i;

	/*
	 * Constructor
	 */
	public FileArrayAdapter(Context context, int textViewResourceId,
			List<option> objects) {
		super(context, textViewResourceId, objects);
		c = context;
		id = textViewResourceId;
		items = objects;

	}

	/*
	 * Overrided function, returns the object
	 */
	public option getitem(int i) {
		return items.get(i);
	}

	/*
	 * Inserted into the function to create a view
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) c
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(id, parent, false);

		}

		final option o = items.get(position);
		if (o != null) {
			TextView t1 = (TextView) v.findViewById(R.id.textView1);
			ImageView i1 = (ImageView) v.findViewById(R.id.imageView1);
			/*
			 * This sets the drawable/folder or drawable/file according to the
			 * item as a folder or a file respetively
			 */
			if (t1 != null) {
				t1.setText(o.getname());
				if (o.getdata().equals("Folder"))
					i1.setImageResource(R.drawable.foldera);
				else if (o.getdata().equals("Parent Directory")) {
					i1.setImageResource(R.drawable.foldera); // Set to
																// Drawable/foldera
				} else
					i1.setImageResource(R.drawable.filea); // Set to
															// drawable/filea

			}
		}
		return v;
	}

}
